package com.c.ctgproject.ui.collect

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.c.ctgproject.base.BaseActivityV2
import com.c.ctgproject.databinding.ActivityMaterialCheckBinding
import com.c.ctgproject.http.ApiMethods
import com.c.ctgproject.http.MyObserverHandlerLoading
import com.c.ctgproject.utils.*

/**
 *作者:LiBW
 *创建日期: 2021/9/18
 *描述: 物料盘点 页面
 */
class MaterialCheckActivity : BaseActivityV2() {
    private val mBinding by lazy { ActivityMaterialCheckBinding.inflate(layoutInflater) }
    override fun getLayout() = mBinding.root
    private val id by lazy { intent.getIntExtra(MyConstants.ID, -1) }
    private val weight by lazy { intent.getStringExtra(MyConstants.WEIGHT) }

    override fun event() {
        mBinding.weight.text = weight.noDataHandler()


    }

    private var method = 3
    override fun click() {
        mBinding.mPY.setOnClickListener { method = 3 }
        mBinding.mPK.setOnClickListener { method = 4 }


        mBinding.mConfirmBTN.setOnClickListener {
            when {
                mBinding.weightDiff.text.handlerNull().isEmpty() -> {
                    showToast("请输入盘点重量")
                    mBinding.mWeightLL.myShake()
                }
                else -> {
                    val map = HashMap<String, Any>()
                    map["stockId"] = id
                    map["method"] = method
                    map["weightDiff"] = mBinding.weightDiff.text.handlerNull()
                    ApiMethods.apiSubscribe(ApiMethods.retrofit.materialCheck(handlerBody(map)), MyObserverHandlerLoading(this, loading) {
                        MyLog.d("回调:$it")
                        showToast("提交成功")
                        finish()
                    })
                }
            }
        }
    }
}